<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>策略模式</title>
</head>
<body>

</body>
</html>

<script>
  /*
  * 将功能用算法封装起来，使用与实现分离（定义多个函数，分别调用）
  * */
  const map = {
    S: 10,
    A: 8,
    B: 6,
    C: 4
  }
  
  const levelMap = {
    basicScore: 80,
    S: function () {
      return this.basicScore + map['S']
    },
    A: function () {
      return this.basicScore + map['A']
    },
    B: function () {
      return this.basicScore + map['B']
    },
    C: function () {
      return this.basicScore + map['C']
    }
  }
  
  function getScore (level) {
    return levelMap[level] ? levelMap[level]() : '辣鸡'
  }

  console.log('D:', getScore('D'))
  console.log('S:', getScore('S'))
</script>